package com.atguigu.controller.api;

import com.atguigu.common.result.R;
import com.atguigu.service.DepartmentService;
import com.atguigu.service.HospitalService;
import com.atguigu.service.HospitalSetService;
import com.atguigu.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private  DepartmentService  departmentService;
    @Autowired
    private HospitalSetService   hospitalSetService;


    @GetMapping("/api_url/{hoscode}")
    public String  apiUrl(@PathVariable  String hoscode ){
        String  apiUrl=hospitalSetService.findApiUrl(hoscode);
          return  apiUrl;
    }
    //首页上查询医院列表
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages", hospitalPage);
    }

    /**
     * 根据医院名称去搜索
     */
    @GetMapping("findByHosname/{hosname}")
    public R findByHosname(@PathVariable String hosname) {
        List<Hospital> list = hospitalService.findByHosname(hosname);
        return R.ok().data("list", list);
    }

    /*
    医院详情接口  点击医院去mondb里面查询医院里的所有信息 科室 排班信息 预约时间
     */
    @GetMapping("{hoscode}")
    public R item(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        //返回的直接是数据 不是map集合
        return R.ok().data(map);
    }

    /***
     *获取医院科室列表
     */

    @GetMapping("department/{hoscode}")
    public R index(@PathVariable  String hoscode) {
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return  R.ok().data("list",list);
    }

    /**
     * 预约挂号详情接口
     */
    @Autowired
    private ScheduleService  scheduleService;
    //日期列表
    //auth/getBookingScheduleRule/
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public  R getBookingSchedule(@PathVariable Integer page,@PathVariable Integer limit, @PathVariable String hoscode,@PathVariable String depcode){
        Map<String,Object> map = scheduleService.getBookingScheduleRule(page,limit,hoscode,depcode);
        return  R.ok().data(map);
    }
    /**
     *  查询排班列 表 (根据医院编号 +科室编号 +日期
     */
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public  R findScheduleList(@PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate){
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return  R.ok().data("scheduleList",scheduleList);

    }

    /**
     * 按照日期排班
     * @param id
     * @return
     */
    @GetMapping("getSchedule/{id}")
    public   R getSchedule(@PathVariable String id){
        Schedule schedule = scheduleService.getById(id);
        return  R.ok().data("schedule",schedule);
    }

    /**
     *
     * @param scheduleId
     * @return
     */
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
   public ScheduleOrderVo  getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        return  scheduleService.getScheduleOrderVo(scheduleId);
   }
}
